import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getAllRolesList } from "/@/views/system/tenantMember/user.api";

export const extLdpColumns: BasicColumn[] = [
  {
    width: 120,
    dataIndex: 'grantType',
    ifShow: false,
  },
  {
    title: '名称',
    width: 120,
    dataIndex: 'name',
  },

  {
    title: '状态',
    width: 64,
    dataIndex: 'checked',
    slot: 'checked'
  },
];


export const columns: BasicColumn[] = [
  {
    title: '客户端名称',
    width: 120,
    dataIndex: 'name',
  },
  {
    title: '客户端ID',
    width: 120,
    dataIndex: 'clientId',
  },
  {
    title: '客户端密钥',
    width: 100,
    dataIndex: 'clientSecret',
  },
  {
    title: '域',
    width: 100,
    dataIndex: 'scope',
  },
  {
    title: '自动放行',
    width: 100,
    dataIndex: 'autoApprove',
    customRender: ({text}) => {
      return text ? '是' : '否'
    }
  },
  {
    title: '令牌失效 (秒)',
    width: 100,
    dataIndex: 'accessTokenValidity'
  },
  {
    title: '刷新失效 (秒)',
    width: 100,
    dataIndex: 'refreshTokenValidity'
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'clientId',
    label: '客户端ID',
    component: 'Input',
    colProps: {span: 8},
  }
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'id',
    component: 'Input',
    show:false
  },
  {
    field: 'isDetail',
    label: 'isDetail',
    component: 'Input',
    show: false
  },
  {
    field: 'name',
    label: '客户端名称',
    component: 'Input',
    required: true
  },
  {
    field: 'clientId',
    label: '客户端ID',
    component: 'Input',
    required: true,
    // ifShow: ({ values }) => {
    //   return !!values.id
    // },
    dynamicDisabled: ({values}) => {
      return !!values.id;
    },
  },
  {
    field: 'clientSecret',
    label: '客户端密钥',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入客户端密钥',
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'authorizedGrantTypes',
    label: '授权模式',
    required: true,
    component: 'JDictSelectTag',
    componentProps: {
      mode: 'multiple',
      dictCode:'authorized_grant_types',
      placeholder:'请选择授权模式',
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    },
  },
  {
    label: '角色',
    field: 'roleIds',
    required: false,
    helpMessage: '用户所拥有的权限为 用户角色 + 客户端角色 的权限',
    component: 'ApiSelect',
    componentProps: {
      mode: "multiple",
      api: getAllRolesList,
      labelField: 'roleName',
      valueField: 'id',
    },
  },
  {
    field: 'scope',
    label: '域',
    defaultValue: 'server',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入域',
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },

  {
    field: 'accessTokenValidity',
    label: '令牌失效 (秒)',
    defaultValue: '604800',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入令牌失效',
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },

  {
    field: 'refreshTokenValidity',
    label: '刷新失效 (秒)',
    defaultValue: '2592000',
    component: 'Input',
    required: true,
    componentProps: {
      placeholder: '请输入刷新失效',
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },

  {
    field: 'autoApprove',
    label: '自动放行',
    component: 'JDictSelectTag',
    defaultValue: '1',
    componentProps: {
      dictCode: 'true_flase',
      type: 'radio',
      dropdownStyle: {
        maxHeight: '6vh',
      },
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'canSameTimeOnline',
    label: '允许同时在线',
    defaultValue: '1',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'true_flase',
      type: "radio",
      dropdownStyle: {
        maxHeight: '6vh',
      },
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'useCaptcha',
    label: '使用验证码',
    defaultValue: '1',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'true_flase',
      type: "radio",
      dropdownStyle: {
        maxHeight: '6vh',
      },
    },
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },

  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    required: false,
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'divider-api-select',
    component: 'Divider',
    label: '连续登录失败设置',
  },
  {
    field: 'loginFailCount',
    label: '登录失败次数',
    defaultValue: '-1',
    helpMessage: '当登录失败达到一定次数之后, 就会被锁定, -1不限制',
    component: 'Input',
    required: false,
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'lockInterval',
    label: '锁定周期',
    helpMessage: '锁定周期(单位为秒)',
    defaultValue: '10',
    component: 'Input',
    required: false,
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },
  {
    field: 'lockMultiplier',
    label: '锁定时间乘子',
    defaultValue: '1',
    helpMessage: '下一次锁定的时间 = 连续被锁定次数 * 锁定周期 * 锁定时间乘子',
    component: 'Input',
    required: false,
    dynamicDisabled: ({values}) => {
      return values.isDetail === '1';
    }
  },

];
